﻿(function ()
{
	nWse.stPageInit.cAddEvtHdlr_DocRdy(function()
	{
		var nMvc = nWse.nMvc;
		var nGui = nWse.nGui;

		var stAppCnsl = nWse.stAppCnsl;

		//-------- 模板函数

		(function ()
		{
			var l_Rgtr = nWse.nGui.stHtmlTmp.c_TmpFctnRgtr;

			l_Rgtr.fRdblPostDatm = function (a_Pdfn, a_Jsons)
			{
				var l_Json = a_Jsons[a_Jsons.length - 1];
				var l_Pd = new Date(l_Json["post_date"]);
				var l_Now = new Date();
				var l_Dta = Math.round(nWse.stDateUtil.cCalcDtaDay(l_Pd, l_Now));
				var l_f2Dgts = nWse.stDateUtil.cTo2DgtsStr;
				var l_PH, l_PM, l_PS, l_NH, l_NM, l_NS;
				l_PH = l_Pd.getHours();
				l_PM = l_Pd.getMinutes();
				l_PS = l_Pd.getSeconds();

				if (0 == l_Dta)
				{
					l_NH = l_Now.getHours();
					l_NM = l_Now.getMinutes();
					l_NS = l_Now.getSeconds();

					if (l_PH < l_NH)
					{
						return (l_NH - l_PH) + "小时前";
					}

					if (l_PM < l_NM)
					{
						return (l_NM - l_PM) + "分钟前";
					}

					return "刚刚";
				}

				if (1 == l_Dta)
				{
					return "昨天 " + nWse.stDateUtil.cHisToStr(l_PH, l_PM, l_PS);
				}

				if (2 == l_Dta)
				{
					return "前天 " + nWse.stDateUtil.cHisToStr(l_PH, l_PM, l_PS);
				}

				return l_Json["post_date"];
			};
		})();

		//-------- 命令

		var l_LogoutSta = 0;
		stAppCnsl.cReg("logout", function(a_Help, a_Istr, a_Agms)
		{
			if (a_Help) { return a_Istr; }

			if (l_LogoutSta)
			{
				return "正在登出";
			}

			l_LogoutSta = 1;
			var l_Ajax = new nWse.tAjax();
			l_Ajax.cSetRqstHdr_FormUrlEcd();
			var l_fAjaxAnmt = nGui.tWgt.sc_fAjaxAnmt;
			if (l_fAjaxAnmt) { l_fAjaxAnmt(l_Ajax, 0, null); }
			l_Ajax.cRqst({
				c_Mthd: "POST",
				c_Url: nWse.fApdUrlQry(g_SiteInfo.c_ApiUrl, "_a=logout"),
				c_fOnCplt: function(a_Ajax, a_IsSucs)
				{
					if (l_fAjaxAnmt) { l_fAjaxAnmt(l_Ajax, a_IsSucs ? +1 : -1, null); }
				},
				c_fOnSucs: function()
				{
					location.href = g_SiteInfo.c_RootUrl;
				},
				c_fOnFail: function()
				{
					l_LogoutSta = 0;
					alert("退出失败，请稍后重试。");
				}
			});		
		});
	});
})();